<template>
    <y-dialog @open="open" @close="emit('close')" width="1000px" append-to-body>
        <el-form ref="closeReqRef" :model="form" :rules="rules" size="default" label-width="120px">
            <el-row>
                <el-col :span="24">
                    <el-form-item label="评审人" prop="reviewers">
                        <y-select v-model="form.reviewers" placeholder="请选择评审人" :optionsFunc="listUser" />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col>
                    <el-form-item label="备注" prop="desc">
                        <el-input v-model="form.remark" type="textarea" :rows="5" placeholder="请输入备注信息" />
                    </el-form-item>
                </el-col>
            </el-row>

        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button type="primary" @click="submit">确定</el-button>
                <el-button @click="emit('close')">取消</el-button>
            </div>
        </template>
    </y-dialog>
</template>

<script setup name="ReviewerSelect">
import { listUser } from "@/api/sys/user";

const { proxy } = getCurrentInstance();

const emit = defineEmits(["submited", "close"]);

const data = reactive({
    form: {},
    rules: {
        reviewers: [{ required: true, message: "需求评审人不能为空", trigger: "blur" }],
    },
});

const { form, rules } = toRefs(data);

const props = defineProps({
    id: { type: String, default: "" },
    getMethod: { type: Function, default: undefined },
    updateMethod: { type: Function, default: undefined },
});

/** 打开对话框事件 */
function open() {
    props.getMethod(props.id).then((res) => {
        form.value = res.data;
        form.value.reviewers = null
    });
}

/** 提交按钮事件 */
function submit() {
    proxy.$refs["closeReqRef"].validate((valid) => {
        if (valid) {
            form.value.status = "reviewing" // 将需求状态置为 “评审中”
            props.updateMethod(form.value).then((res) => {
                proxy.$modal.msgSuccess("添加评审人成功");
                submited()
            });
        }
    });
}

/** submited事件 */
function submited() {
    emit('submited')
    emit('close')
}
</script>
